    <div class="nav-sub w1180">
    	<ul class="zoom">
    		<li><a class="on" href="/crm/order/index">订单管理</a></li>
    		<li><a href="/crm/order/return">退货管理</a></li>
    		<li><a href=/crm/order/cancel>取消订单管理</a></li>
    	</ul>
    </div>
	<div class="main-ct w1180">

		<div class="top-bar">
			<div class="custom-search">
				<label>订单号<input id="order_no" style="width:150px;" type="text" class="tp-txt" ></label>
				<label>订单类型<select class="category-select" id="order_type">
					<option value="">未分类</option>
					<option value="1">配餐</option>
					<option value="2">商城</option>
				</select></label>
				<label>城市<select class="category-select" id="city_id">
					<option value="">未分类</option>
					<?php foreach ($this->city as $city):?>
					<option value="<?php echo $city['city_id'];?>"><?php echo $city['city_name'];?></option>
					<?php endforeach;?>
				</select></label>
				<label>商户类型<select class="category-select" id="catalog_id" style="width:80px;">
					<option value="">未分类</option>
					<?php foreach ($this->catalog as $catalog):?>
					<option value="<?php echo $catalog['catalog_id'];?>"><?php echo $catalog['catalog_name'];?></option>
					<?php endforeach;?>
				</select></label>
				<label>商户<select class="category-select" id="org_id" style="width:160px;">
					<option value="">未分类</option>
					<?php foreach ($this->organization as $organization):?>
					<option value="<?php echo $organization['org_id'];?>"><?php echo $organization['org_name'];?></option>
					<?php endforeach;?>
				</select></label>
				<label>订单状态<select class="category-select" id="status">
					<option value="">未分类</option>
					<option value="1">待付款</option>
					<option value="2">待发货</option>
					<option value="3">已发货</option>
					<option value="4">已取消</option>
<!-- 					<option value="5">订单订单</option> -->
				</select></label>
				<label>开始日期<input style="width:95px;" id="start_time" type="text" class="tp-txt" onFocus="WdatePicker({isShowClear:true,readOnly:true})"></label>
				<label>结束日期<input style="width:95px;" id="end_time" type="text" class="tp-txt" onFocus="WdatePicker({isShowClear:true,readOnly:true})"></label>
				<a href="javascript:search();" class="btn-cs btn-search ml5">查 询</a>
				<a href="javascript:outExcel();" class="btn-cs btn-green ml5">导出订单</a>
				<a href="javascript:batchSend();" class="btn-cs btn-blue ml5">配餐批量发货</a>
			</div>
		</div>
		<div class="row" id="order_list_table">

		</div>
	</div>
	

	<!-- Modal -->
	<div class="modal" id="sendOrder" tabindex="-1" role="dialog" >
		<div class="modal-body">
			<button class="close" type="button" data-dismiss="modal">×</button>
			<form class="form-horizontal mt20" role="form">
			<input type="hidden" id="send_order_id" >
				<div class="form-group">
					<label for="inputEmail3" class="col-sm-2 control-label">快递名称</label>
					<div class="col-sm-10" style="width: 380px;">
						<input type="text" class="form-control" id="express_name" placeholder="快递名称">
					</div>
				</div>
				<div class="form-group">
					<label for="inputEmail3" class="col-sm-2 control-label">快递单号</label>
					<div class="col-sm-10" style="width: 380px;">
						<input type="text" class="form-control" id="express_no" placeholder="快递单号">
					</div>
				</div>
			</form>

			<button id="send_order" type="button" class="btn btn-primary fr">确定</button>

		</div>
	</div>
	<!-- Modal -->
	<div class="modal" id="refundMoney" tabindex="-1" role="dialog" >
		<div class="modal-body">
			<button class="close" type="button" data-dismiss="modal">×</button>
			<form class="form-horizontal mt20" role="form">
			<input type="hidden" id="refund_order_id" >
			<input type="hidden" id="total_price" >
				<div class="form-group">
					<label for="inputEmail3" class="col-sm-2 control-label">退款金额</label>
					<div class="col-sm-10" style="width: 380px;">
						<input type="number" class="form-control" id="refundPrice" placeholder="元">
					</div>
				</div>
<!-- 				<div class="form-group"> -->
<!-- 					<label for="inputEmail3" class="col-sm-2 control-label">Email</label> -->
<!--					<div class="col-sm-10" style="width: 380px;"> -->
<!-- 						<input type="email" class="form-control" id="inputEmail3" placeholder="Email"> -->
<!-- 					</div> -->
<!-- 				</div> -->
			</form>
			<button id="refund_money" type="button" class="btn btn-primary fr">确定</button>
		</div>
	</div>
	
	
<script src="/plugins/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
var page = 1;
var order_no = $("#order_no").val();
var order_type = $("#order_type").val();
var city_id = $("#city_id").val();
var catalog_id = $("#catalog_id").val();
var org_id = $("#org_id").val();
var status = $("#status").val();
var start_time = $("#start_time").val();
var end_time = $("#end_time").val() ;

$(document).ready(function(){
	ajaxListTable();
});

function search(){
	page = 1;
	order_no = $("#order_no").val();
	order_type = $("#order_type").val();
	city_id = $("#city_id").val();
	catalog_id = $("#catalog_id").val();
	org_id = $("#org_id").val();
	status = $("#status").val();
	start_time = $("#start_time").val();
	end_time = $("#end_time").val() ;

	ajaxListTable();
}
function outExcel(){
	window.location.href="/crm/order/excel-order?"+ 
	'order_no=' + order_no + 
	'&order_type=' + order_type + 
	'&city_id=' + city_id + 
	"&catalog_id=" + catalog_id + 
	"&org_id=" + org_id + 
	"&status=" + status + 
	"&start_time=" + start_time + 
	"&end_time=" + end_time;
}

function ajaxListTable(){
	$.ajax({
        type: "post",
        url : "<?php echo $this->url('crm/order',
            array('action'=>'ajax-order-list-table'));?>",
        dataType:'html',
        data:  { 
            "order_no": order_no, 
            "order_type": order_type, 
            "city_id": city_id, 
            "catalog_id": catalog_id, 
            "org_id": org_id, 
            "status": status, 
			"start_time": start_time, 
			"end_time": end_time,
			"page":page },
        cache: false,
        timeout:10000, 
        error: function(){
          	 alert('请求超时，请重新操作');
           	 isPost = false;
             return false; 
         }, 
        success: function(html){
        	$("#order_list_table").html(html);
        }
    });
}

function sendOrder(order_id,order_type,express_no,express_name){

	if(order_type == '2'){
		$('#send_order_id').val(order_id);
		$('#express_no').val(express_no);
		$('#express_name').val(express_name);
		$('#sendOrder').modal('show');
	}else{
		$.ajax({
	        type: "post",
	        url : "<?php echo $this->url('crm/order',
	            array('action'=>'send-order'));?>",
	        dataType:'json',
	        data:  { 
	            "order_id": order_id, 
	            "order_type": '1', 
	            "express_no": '',
	            "express_name": '', 
	             },
	        cache: false,
	        timeout:10000, 
	        error: function(err){
	        	alert('请求超时，请重新操作');
	            return false; 
	       }, 
	      success: function(result){
	          alert(result.reason);
	          $('#sendOrder').modal('hide');
	          ajaxListTable();
	      }
	    });
	}
}
$("#send_order").click(function(){
    var express_no = $('#express_no').val();
    var express_name = $('#express_name').val();
    if(express_name == ""){
    	alert('请填写快递名称！');
    	return;
    }
    if(express_no == ""){
    	alert('请填写快递单号！');
    	return;
    }
    
	$.ajax({
        type: "post",
        url : "<?php echo $this->url('crm/order',
            array('action'=>'send-order'));?>",
        dataType:'json',
        data:  { 
            "order_id": $('#send_order_id').val(), 
            "order_type": '2', 
            "express_no": express_no,
            "express_name": express_name, 
             },
        cache: false,
        timeout:10000, 
        error: function(){
        	alert('请求超时，请重新操作');
            return false; 
       }, 
      success: function(result){
          alert(result.reason);
          $('#sendOrder').modal('hide');
          ajaxListTable();
      }
    });

});
function refundMoney(order_id,total_price){
	$('#refund_order_id').val(order_id);
	$('#total_price').val(total_price);
 	$('#refundMoney').modal('show');
}
$("#refund_money").click(function(){
    var total_price = $('#total_price').val();
    var refundPrice = $('#refundPrice').val();
    if(refundPrice == ""){
    	alert('请填写退款金额！');
    	return;
    }
    if(refundPrice > total_price){
    	alert('退款金额不能大于订单金额！');
    	return;
    }
    
	$.ajax({
        type: "post",
        url : "<?php echo $this->url('crm/order',
            array('action'=>'refund-money'));?>",
        dataType:'json',
        data:  { 
            "order_id": $('#refund_order_id').val(), 
            "refund_price": refundPrice,
             },
        cache: false,
        timeout:10000, 
        error: function(){
        	alert('请求超时，请重新操作');
            return false; 
       }, 
      success: function(result){
          alert(result.reason);
          $('#refundMoney').modal('hide');
          ajaxListTable();
      }
    });
});
//批量发货
function batchSend(){

//     if(status != '2'){
//     	alert('请查询待发货订单！');
//     	return;
//     }

    if(!confirm("确认对查询结果批量发货？请谨慎使用！")){
        return;
    }
    
	$.ajax({
        type: "post",
        url : "<?php echo $this->url('crm/order',
            array('action'=>'batch-send'));?>",
        dataType:'json',
        data:  { 
            "order_no": order_no, 
            "order_type": order_type, 
            "city_id": city_id, 
            "catalog_id": catalog_id, 
            "org_id": org_id, 
            "status": status, 
			"start_time": start_time, 
			"end_time": end_time,
			//"page":page 
			},
        cache: false,
        timeout:10000, 
        error: function(err){
          	 alert('请求超时，请重新操作');
             return false; 
         }, 
        success: function(result){
            alert(result.reason);
            ajaxListTable();
        }
    });
}
</script>